package com.arena.model;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Question {
	private String question;
	private String[] answers;
	public Question(JSONObject data) {
		if (data == null) {
			return;
		}
		try {
			setQuestion(data.getString("question"));
		} catch (JSONException e) {			
			e.printStackTrace();
			setQuestion("");
		}		
		try {
			JSONArray jsAnswers = data.getJSONArray("answers");
			setAnswers(new String[jsAnswers.length()]);
			for (int index = 0; index < jsAnswers.length(); index++) {
				getAnswers()[index] = jsAnswers.getString(index);
			}			
		} catch (JSONException e) {
			e.printStackTrace();
			setAnswers(new String[]{});
		}
	}
	
	public String getQuestion() {
		return question;
	}
	void setQuestion(String question) {
		this.question = question;
	}
	public String[] getAnswers() {
		return answers;
	}
	void setAnswers(String[] answers) {
		this.answers = answers;
	}
	public String getAnswersString() {
		String sAnswers = "";
		for (int i = 0; i < answers.length; i++) {
			sAnswers += answers[i];
		}
		return sAnswers;
	}
	
}
